/**
 * @author joseph
 * @since 6/17/12 8:58 PM
 */
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.image.BufferedImage;
import java.io.File;

public class MainSwingFrame extends JFrame {
    private BufferedImage bi;

    private int zoom = 0;

    private static final double ZOOM_AMOUNT = 1.1;

    public static void main(String[] args) {
        new MainSwingFrame("/home/joseph/workspace/idea/hunting/map.png").setVisible(true);
    }

    private void sizeToZoom() {
        double factor = Math.pow(ZOOM_AMOUNT, zoom);
        setSize((int) (this.getWidth() * factor), (int) (this.getHeight() * factor));

    }

    public MainSwingFrame(String filename) {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        try {
            bi = ImageIO.read(new File(filename));
        } catch (Exception e) {
            e.printStackTrace();
        }
        setSize(bi.getWidth(),bi.getHeight());
        sizeToZoom();

        addMouseWheelListener(new MouseWheelListener() {
            public void mouseWheelMoved(MouseWheelEvent e) {
                zoom = e.getWheelRotation();
                sizeToZoom();
            }
        });
    }

    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(bi, 0, 0, getWidth(), getHeight(), this);

    }
}

